//
//  MethodClass.m
//  ShopDemo
//
//  Created by 飞扬的青春 on 2018/7/4.
//  Copyright © 2018年 飞扬的青春. All rights reserved.
//

#import "MethodClass.h"

@implementation MethodClass


// 服务器地址
+ (NSString *)returnUrlSetStrWSDLURL:(NSString *)strWSDLURL
{
    NSString *urlStr = [NSString stringWithFormat:@"%@%@",URL_Http,strWSDLURL];
    return urlStr;
}

+ (NSDictionary *)dictionaryWithJsonString:(NSString *)jsonString {
    if (jsonString == nil) {
        return nil;
        
    }
    NSData *jsonData = [jsonString dataUsingEncoding:NSUTF8StringEncoding];
    NSError *err;
    NSDictionary *dic = [NSJSONSerialization JSONObjectWithData:jsonData
                                                        options:NSJSONReadingMutableContainers
                                                          error:&err];
    if(err) {
        NSLog(@"json解析失败：%@",err);
        return nil;
    }
    return dic;
}




/// 正则--电话号码
+ (BOOL)utilityCheckPhoneNumInput:(NSString *)str {
    NSString * num = @"^1[3|4|5|7|8][0-9]\\d{8}$";
    NSPredicate *regextestnum = [NSPredicate predicateWithFormat:@"SELF MATCHES %@",num];
    
    BOOL res1 = [regextestnum evaluateWithObject:str];
    
    if (res1)
    {
        return YES;
    }
    else
    {
        return NO;
    }
    
}


+ (void)verificationCode:(long long)time blockYes:(void(^)(void))blockYes blockNo:(void(^)(id time))blockNo
{
    __block long long timeout = time; //倒计时时间
    dispatch_queue_t queue = dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0);
    dispatch_source_t _timer = dispatch_source_create(DISPATCH_SOURCE_TYPE_TIMER, 0, 0,queue);
    dispatch_source_set_timer(_timer,dispatch_walltime(NULL, 0),1.0*NSEC_PER_SEC, 0); //每秒执行
    dispatch_source_set_event_handler(_timer, ^{
        if(timeout<=0){
            //倒计时结束，关闭
            dispatch_source_cancel(_timer);
            dispatch_async(dispatch_get_main_queue(), ^{
                //设置界面的按钮显示 根据自己需求设置
                blockYes();
            });
        }else{
            
            // int minutes = timeout / 60;
            //           int seconds = timeout % 60;
            //           NSString *strTime = [NSString stringWithFormat:@"%.2d", seconds];
            //            NSInteger minutes = timeout --;
            NSString *strTime = [NSString stringWithFormat:@"%lld",timeout];
            dispatch_async(dispatch_get_main_queue(), ^{
                //设置界面的按钮显示 根据自己需求设置
                blockNo(strTime);
            });
            timeout--;
        }
        
        
    });
    dispatch_resume(_timer);
    
    
}


@end
